% V20210224 - 9.19.3 GW_SHOW_WRONG_PATTERN INCLUDE "GW.bas" define$ = "Define a new lock pattern:" draw$ = "Draw your lock pattern to access the app." confirm$ = "Confirm the existing lock pattern:" % Create a page in dark mode. GW_USE_THEME_CUSTO_ONCE("color=b") p = GW_NEW_PAGE() % Prepare title bar string. Title$ = GW_ADD_BAR_TITLE$("Top Secret App") % Add title to page. GW_ADD_TITLEBAR(p, Title$) % Add text. txt = GW_ADD_TEXT(p, define$) % Add Lock Pattern control. lock = GW_ADD_LOCK_PATTERN(p, "") % Add a colored button. GW_USE_THEME_CUSTO_ONCE("style='background:red'") del_btn = GW_ADD_BUTTON(p, "Modify the lock pattern", "DEL") GW_ADD_BUTTON(p, "Cancel and Exit App", "BACK") % Now show the page. GW_RENDER(p) % Immediately hide the Modify button depending on the situation. FILE.EXISTS fe, "lock.pattern" IF fe % lock pattern already saved TEXT.OPEN r, fid, "lock.pattern" TEXT.READLN fid, saved_pattern$ TEXT.CLOSE fid PRINT "Existing code: "+CHR$(34)+saved_pattern$+CHR$(34) GW_MODIFY(txt, "text", draw$) ELSE GW_HIDE(del_btn) ENDIF DO % Wait for user action. r$ = GW_WAIT_ACTION$() % Received a message from the lock pattern control. IF IS_IN("pattern:", r$) = 1 % Save drawn pattern in a variable. drawn_pattern$ = MID$(r$, LEN("pattern:")+1) PRINT "Received code: "+CHR$(34)+drawn_pattern$+CHR$(34) % Handle saving a new pattern. IF saved_pattern$ = "" % Very first pattern draw: IF first_pattern$ = "" first_pattern$ = drawn_pattern$ % Clear the pattern on screen GW_CLEAR_LOCK_PATTERN(lock) % And ask for pattern confirmation POPUP "Please confirm pattern" PRINT "Asking code confirmation" % Second pattern draw: matches first :) ELSEIF drawn_pattern$ = first_pattern$ % Clear the pattern on screen GW_CLEAR_LOCK_PATTERN(lock) % Save the code to a file saved_pattern$ = drawn_pattern$ TEXT.OPEN w, fid, "lock.pattern" TEXT.WRITELN fid, saved_pattern$ TEXT.CLOSE fid % Show success to user POPUP "Code defined" PRINT "Saved code: "+CHR$(34)+saved_pattern$+CHR$(34) % And prepare for the next steps GW_ENABLE(del_btn) GW_SHOW(del_btn) GW_MODIFY(txt, "text", draw$) % Second pattern drawn: doesn't match first :( ELSE % Show failure to user GW_SHOW_WRONG_PATTERN(lock) POPUP "Wrong pattern!\nTry again" PRINT "Wrong code" % Wait 2s before clearing the (wrong) pattern PAUSE 2000 GW_CLEAR_LOCK_PATTERN(lock) ENDIF % User drew correctly the saved pattern ELSEIF drawn_pattern$ = saved_pattern$ % He previously asked to delete it > granted IF ask_to_delete % Show sucess to user ask_to_delete = 0 GW_CLEAR_LOCK_PATTERN(lock) POPUP "Confirmed!\nReseting access..." % Delete code from disk and variable FILE.DELETE fd, "lock.pattern" saved_pattern$ = "" first_pattern$ = "" % Proceed to recording a new code GW_HIDE(del_btn) GW_MODIFY(txt, "text", define$) PRINT "Code reset - File deleted" % Default case: correct code grants access to the top secret page! ELSE GOTO TopSecret ENDIF % User drew a pattern other than the saved one ELSE % Inform user GW_SHOW_WRONG_PATTERN(lock) IF ask_to_delete THEN POPUP "Wrong lock pattern!\nOperation cancelled" % Wait 1s and clear the pattern on screen PAUSE 1000 GW_CLEAR_LOCK_PATTERN(lock) % If pattern was needed for a reset operation, cancel IF ask_to_delete ask_to_delete = 0 GW_MODIFY(txt, "text", draw$) GW_ENABLE(del_btn) ENDIF ENDIF % end of pattern treatment % User pressed the "Modify lock pattern" button ELSEIF r$ = "DEL" % Ask user for existing code to confirm operation ask_to_delete = 1 GW_MODIFY(txt, "text", confirm$) POPUP "Existing code needed" GW_DISABLE(del_btn) ENDIF UNTIL r$ = "BACK" % End when BACK key is pressed. END "End of Lock Pattern example."